package com.wzw.springboot.principle.lifecycle.bean;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Wangzhiwen
 */
@Configuration
public class BeanLifeCycle {

    /**
     * 使用@Bean方式执行初始化与销毁方法
     */
    @Bean(initMethod = "bean1Init", destroyMethod = "beanDestroy")
    public Bean1 bean1() {
        Bean1 bean1 = new Bean1();
        bean1.setAge(1);
        bean1.setName("bean1");
        System.out.println("bean1 constructor init...........");
        return bean1;
    }

    /**
     * Bean实现接口
     */
    @Bean
    public Bean2 bean2() {
        Bean2 bean2 = new Bean2();
        bean2.setAge(2);
        bean2.setName("bean2");
        System.out.println("bean2 constructor init............");
        return bean2;
    }

    /**
     * 使用 JSR250 注解
     */
    @Bean
    public Bean3 bean3() {
        Bean3 bean3 = new Bean3();
        bean3.setAge(3);
        bean3.setName("bean3");
        System.out.println("bean2 constructor init............");
        return bean3;
    }

}
